package ${packageName};

<#list imports as import>
import ${import};
</#list>

/**
 * @ClassName:  CBiz${underlineToCamel(sourceTable?lower_case,true?string)}
 * @Description:TODO(商业实体对象:C${underlineToCamel(sourceTable?lower_case,true?string)}Entity对应提供的服务具体实现)
 * @author: 李启联
 * @date:   ${.now}
 * @version V1.0
 * @Copyright: Copyright (c) 2018
 * 申明：本内容未经作者本人同意,禁止外泄以及用于其他的商业项目.
 */
@Service
@CacheConfig(cacheNames="Biz${underlineToCamel(sourceTable?lower_case,true?string)}_Cache")
public class CBiz${underlineToCamel(sourceTable?lower_case,true?string)} implements IBiz${underlineToCamel(sourceTable?lower_case,true?string)} {

    @Autowired
    private C${underlineToCamel(sourceTable?lower_case,true?string)}Repository access;

    @Override
    @Cacheable()
    public EntityCollection find${underlineToCamel(sourceTable?lower_case,true?string)}Collections(Map<String,Object> filter) throws Exception {
        AccessParameter parameter = new AccessParameter();
        parameter.getFilter().addAllEqual(filter);
        return access.searchEntityCollection(parameter);
    }

    @Override
    @Cacheable()
    public List<C${underlineToCamel(sourceTable?lower_case,true?string)}Entity> find${underlineToCamel(sourceTable?lower_case,true?string)}List(Map<String,Object> filter) throws Exception {
        AccessParameter parameter =  new AccessParameter();
        parameter.getFilter().addAllEqual(filter);
        return (List<C${underlineToCamel(sourceTable?lower_case,true?string)}Entity>) access.searchEntityList(parameter);
    }


    @Override
    @Cacheable()
    public List<C${underlineToCamel(sourceTable?lower_case,true?string)}Entity> find${underlineToCamel(sourceTable?lower_case,true?string)}ListBySql(CommandType commandType, String commandText, Object... obj) throws Exception {
        return (List<C${underlineToCamel(sourceTable?lower_case,true?string)}Entity>) access.searchEntityListBySQL(commandType,commandText,obj);
    }

    @Override
    @Cacheable(key="#root.targetClass+':'+#root.methodName+':'+#filter+':'+#pageIndex+':'+#pageSize")
    public  PageInfo<C${underlineToCamel(sourceTable?lower_case,true?string)}Entity> find${underlineToCamel(sourceTable?lower_case,true?string)}ForPageInfo(Map<String, Object> filter, Map<String, String> sorter,
       Integer pageIndex, Integer pageSize) throws Exception {

        AccessParameter parameter =  new AccessParameter();

        if(null != filter)
        parameter.getFilter().addAllEqual(filter);
        if(null != sorter)
        parameter.getSorter().add(sorter);

        parameter.setPageSize(pageSize);
        parameter.setPageIndex(pageIndex);

        return access.searchEntityPageInfo(parameter);
    }

    @Override
    @Cacheable()
    public PageInfo<C${underlineToCamel(sourceTable?lower_case,true?string)}Entity> find${underlineToCamel(sourceTable?lower_case,true?string)}ForPageInfo(AccessParameter parameter) throws Exception {
        return access.searchEntityPageInfo(parameter);
    }

    @Override
    @Cacheable(key="#id")
    public  C${underlineToCamel(sourceTable?lower_case,true?string)}Entity find${underlineToCamel(sourceTable?lower_case,true?string)}ById(String id) throws Exception {
        AccessParameter parameter = new AccessParameter();
        parameter.getFilter().addEqual(C${underlineToCamel(sourceTable?lower_case,true?string)}Tags.PrimaryKey,id);
        return (C${underlineToCamel(sourceTable?lower_case,true?string)}Entity) access.searchEntity(parameter);
    }

    @Override
    @Cacheable()
    public C${underlineToCamel(sourceTable?lower_case,true?string)}Entity find${underlineToCamel(sourceTable?lower_case,true?string)}ByFieldName(String fieldName, Object val) throws Exception {
        AccessParameter parameter = new AccessParameter();
        parameter.getFilter().addEqual(fieldName,val);
        return (C${underlineToCamel(sourceTable?lower_case,true?string)}Entity) access.searchEntity(parameter);
    }

    @Override
    @Cacheable()
    public C${underlineToCamel(sourceTable?lower_case,true?string)}Entity find${underlineToCamel(sourceTable?lower_case,true?string)}(AccessParameter parameter) throws Exception {
        return (C${underlineToCamel(sourceTable?lower_case,true?string)}Entity) access.searchEntity(parameter);
    }

    @Override
    @Cacheable(key = "#ids")
    public List<C${underlineToCamel(sourceTable?lower_case,true?string)}Entity> find${underlineToCamel(sourceTable?lower_case,true?string)}ListByIds(List<? extends Serializable> ids) throws Exception {
        return (List<C${underlineToCamel(sourceTable?lower_case,true?string)}Entity>) access.searchEntityListByIds(ids);
    }

    @Override
    @Cacheable()
    public Map<String, Object> find${underlineToCamel(sourceTable?lower_case,true?string)}ForMapById(String id) throws Exception {
        return access.getMapById(id);
    }

    @Override
    @CachePut(key = "#p0.id")
    public boolean insert(C${underlineToCamel(sourceTable?lower_case,true?string)}Entity entity) throws Exception {
    return access.insert(entity);
    }

    @Override
    @CachePut(key = "#p0.id")
    public boolean update(C${underlineToCamel(sourceTable?lower_case,true?string)}Entity entity) throws Exception {
        return access.update(entity);
    }

    @Override
    @CachePut(key = "#p0.id")
    public boolean updateWithSelective(C${underlineToCamel(sourceTable?lower_case,true?string)}Entity entity) throws Exception {
        return access.updateWithSelective(entity);
    }

    @Override
    @CacheEvict(key = "#p0.id")
    public boolean delete(C${underlineToCamel(sourceTable?lower_case,true?string)}Entity entity) throws Exception {
        return access.delete(entity);
    }

    @Override
    @CacheEvict(key = "#keyValue")
    public boolean deleteByIdForSingle(Object keyValue) throws Exception {
        return access.deleteByIdForSingle(keyValue);
    }

    @Override
    @CacheEvict(key = "#ids")
    public boolean deleteBatchByIds(List<? extends Serializable> ids, boolean recursive) throws Exception {
        return access.deleteBatchByIds(ids,recursive);
    }

    @Override
    @CacheEvict(key = "#ids")
    public boolean deleteBatchByIds(List<? extends Serializable> ids) throws Exception {
        return deleteBatchByIds(ids,true);
    }

}